package com.itqf.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * projectName: springframeworkgp8
 *
 * @author: 赵伟风
 * time: 2021/8/3 11:13
 * description: 判断window
 */
public class WindowCondition implements Condition {
    /**
     * 判断条件的方法!
     *    true 创建bean并放入同期
     *    false 不创建
     *
     *  context: context上下文信息 环境变量
     *  metadata: 当前注解的信息
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {


        //1.获取全局环境变量对象
        Environment environment = context.getEnvironment();

        String name = environment.getProperty("os.name");

        System.out.println("name = " + name);

        if (name.contains("Windows")){

            return true;
        }

        return false;
    }
}
